package com.lark.wifi.util;

import android.app.Instrumentation;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class KeyControl {


    private static KeyControl instance;

    public static KeyControl getInstance() {
        if (instance == null) {
            synchronized (KeyControl.class) {
                if (instance == null) {
                    instance = new KeyControl();
                }
            }
        }
        return instance;
    }


    private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
    ExecutorService executor = Executors.newFixedThreadPool(CPU_COUNT * 2);

    public void sendMessageTo(int code) {
        if (code < 0) {
            return;
        }
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                Instrumentation inst = new Instrumentation();
                inst.sendKeyDownUpSync(code);
            }
        };
        executor.execute(runnable);
    }

}
